<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>创建合同订单</title>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <script src="${ctxStatic}/js/DateTimePicker.js"></script>
    <script src="${ctxStatic}/js/layer.js"></script>
    <script src="${ctxStatic}/js/style.js"></script>
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <link rel="stylesheet" href="${ctxStatic}/css/common.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script type="text/javascript">
    $(document).ready(function(){
    	var form = $("#inputForm");  
        form.validate();//验证指定的表单
    	$("#userGroupID2").select2();
    	$("#userGroupID").select2();
    	$("#userGroupID2").attr("disabled","disabled");
   		$("#okButton").click(function(){
    		if (form.valid()) {//如果表单验证成功，则进行提交。  
    		/* $("#showHtml").addClass("showHtml");
            $("#okHead").show();
            $("#createHead").hide();  
            $("#advanceDueDate").removeClass("laydate-icon");
            $("#appDate").removeClass("laydate-icon");
            return false; */
            saveTSYForm();
          	}
     	});
    });
    
    /* 保存创建/编辑信息 */
    function saveTSYForm(){
    	//获取 iframe 数量 
     	var frLength = window.parent.frames.length;
     	//父画面下标 
     	var parentIndex = frLength-2;
    	formUnFormat($("#inputForm"));
    	var paramTSY = $("#inputForm").serialize();
    	$.post("${ctx}/produce/notice/save",paramTSY,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
	    	tipParent(result.message);
    		if (result != "false" ) {
	    		if(window.parent.frames[parentIndex].commitPlan && typeof(window.parent.frames[parentIndex].commitPlan) == "function"){
	        		window.parent.frames[parentIndex].commitPlan();
	    		}
	    		window.parent.frames[0].searchListForm();
	    		closeWin();
			}
    	},'json');
    }
    // 合同订单选择回调
    function selectIndentCallBack(indentId){ 
		var param = {
				"indentId" : indentId
			};
        // 调用后台更新数据
        $.post("${ctx}/produce/notice/form",param,function(result) {
            // 回调函数赋值
            var h = $(callBackHtml(result)).find("#orderMaterierInfo").html();
            $('#orderMaterierInfo').html(h);
        }, 'html');
    }
    /* 动态计算日期  */
    function timeFun(t){
   		var period = $("#noticePeriod").val();
   		var beginDate = $("#noticeBeginDate").val();
   		var endDate = $("#noticeEndDate").val();
   		//计划生产周期    投产日期
   		if (t == "noticePeriod" || t == "noticeBeginDate") {
			if (beginDate != "" && period != "") {
				if (parseFloat(period) >= parseFloat(1)) {
		   			period = parseFloat(period) - parseFloat(1);
				}else{
					period = 0;
				}
				var nd = new Date(beginDate);
			   	nd = nd.valueOf();
			   	nd = nd + parseFloat(period) * 24 * 60 * 60 * 1000;
			   	nd = new Date(nd);
			   	var y = nd.getFullYear();
			   	var m = nd.getMonth()+1;
			   	var d = nd.getDate();
			   	if(m <= 9) m = "0"+m;
			   	if(d <= 9) d = "0"+d; 
			   	var cdate = y+"-"+m+"-"+d;
			   	$("#noticeEndDate").val(cdate);
			}else{
				return;
			}
		//完成日期
		}else if (t == "noticeEndDate") {
			if (beginDate != null && beginDate != "") {
				var nbd = new Date(beginDate);
				var ned = new Date(endDate);
				nbd = nbd.valueOf();
				ned = ned.valueOf();
			   	$("#noticePeriod").val((ned-nbd)/(24 * 60 * 60 * 1000)+1);
			}else{
				return;
			}
		}
    }
    </script>
    <style type="text/css">
    .linkBox{
	color:#0a6dca;
	cursor:pointer;
	text-decoration:underline;
	}
	.showHtml input{
	border:none;
	background-color:inherit;
	color:#333;
	}
    </style>
</head>
<body>   
<form id="inputForm">
<div id="createHead" class="layerHeader clearfix">
<c:choose>
	   <c:when test="${produceNotice.id!=null && produceNotice.id!=''}">
	    <!-- 编辑 --> 
			<p class="headerTitle">编辑生产通知单</p>
       </c:when>
       <c:otherwise>
        <!-- 创建 --> 
            <p class="headerTitle">创建生产通知单</p>
       </c:otherwise>
    </c:choose>
	
    <div class="headerButton clearfix">
        <!-- 确定 -->
        <button type="button" id="okButton"><spring:message code="purchaseAdvance_edit_ok"/></button>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>
<!-- 确认画面头部 -->
<div id="okHead" class="layerHeader clearfix" style="display: none;">	      
             <p class="headerTitle">订单计划排期</p>    
    <div class="headerButton clearfix">
	    <!-- 编辑 保存 --> 
			<button type="button" onclick="saveTSYForm();"><spring:message code="common_save" /></button>
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="purchaseAdvance_edit_cancle"/></button>
    </div>
</div>

<div id="showHtml" class="smOrderBox">
        <input type="hidden" id="id" name="id" value="${produceNotice.id }">
		<c:if test="${producePlan.id != null&&producePlan.id!=0}">
    <div class=" clearfix" >
        	<!-- 计划排期信息  -->
        	<p class="title" style="margin-top: 2px">计划排期信息</p>
        </div>
    <div class="items clearfix showHtml">
        <div class="col-33 clearfix">
        <!-- 计划订单编码 -->
            <p class="tit" style="width: 80px">计划订单编码</p>
            <input type="hidden" id="planID" name="planID" value="${producePlan.id }">
            <label>${producePlan.ognizationName }</label>
        </div>
        <div class="col-33 clearfix">
        <!-- 计划订单数量 -->
            <p class="tit" style="width: 80px">计划订单数量</p>
             <label>${producePlan.planQuantity }</label>
        </div>
        <div class="col-33 clearfix">
        <!-- 客户名称 -->
            <p class="tit" style="width: 80px">客户名称</p>
             <label>${producePlan.ognizationName }</label>
        </div>
        
    </div>
    <div class="items clearfix showHtml">
        <div class="col-33 clearfix">
        <!-- 计划生产班组  -->
            <p class="tit" style="width: 80px">计划生产班组</p>
            <select id="userGroupID2" style="width: 150px">
                   <option value=""><spring:message code="order_please_choose"/></option>
                   <c:forEach items="${groupList}" var="group">
                       <option value="${group.userGroupID}" <c:if test="${producePlan.userGroupID eq group.userGroupID }">selected="selected"</c:if>>${group.groupName}</option>
                   </c:forEach>
            </select>
        </div>
         <div class="col-33 clearfix">
                <!-- 单人生产效率 -->
                    <p class="tit" style="width: 80px">单人生产效率</p>
                    <label>${producePlan.planEfficiency }</label>&ensp;(件/人)
                </div>
        <div class="col-33 clearfix">
                <!-- 计划投产人数  -->
                    <p class="tit" style="width: 80px">计划投产人数</p>
                    <label>${producePlan.planNumber }</label>&ensp;(人)
                </div>
   		</div>
    
            <div class="items clearfix showHtml">        	
                <div class="col-33 clearfix">
                <!-- 计划生产周期  -->
                    <p class="tit" style="width: 80px">计划生产周期</p>
                    <label>${producePlan.planPeriod }</label>&ensp;(天)
                </div>                	
                <div class="col-33 clearfix">
                <!-- 计划投产日期 -->
                    <p class="tit" style="width: 80px">计划开始日期</p>
                    <label><fmt:formatDate value="${producePlan.planBeginDate }" pattern="yyyy-MM-dd" /></label>
                </div>
                <div class="col-33 clearfix">
                <!-- 计划清活日期 -->
                    <p class="tit" style="width: 80px">计划清活日期</p>
                    <label><fmt:formatDate value="${producePlan.planEndDate }" pattern="yyyy-MM-dd" /></label>
                </div>
            </div>
            <div class="items clearfix showHtml">
            	<div class="col-33 clearfix">
                <!-- 计划交货日期 -->
                    <p class="tit" style="width: 80px">计划交货日期</p>
                    <label><fmt:formatDate value="${producePlan.planDeliveryDate }" pattern="yyyy-MM-dd" /></label>
                </div>
            </div>
            <div class="items clearfix showHtml">
                
        		<div class="items clearfix">
        		<!-- 备注 -->
            		<p class="tit" style="width: 80px">备&ensp;&ensp;&ensp;&ensp;注</p>
            		<textarea style="width:750px;height: 50px">${producePlan.remarks }</textarea>
        		</div>
    	</div>
    	</c:if>
    	<div class=" clearfix" >
        	<!-- 生产通知单信息  -->
        	<p class="title" style="margin-top: 2px">生产通知单信息</p>
        </div>
 <div id="orderMaterierInfo" <c:if test="${produceNotice.id != null }">class="showHtml"</c:if>>
 <c:if test="${produceNotice.noticeFlag != '1'}">
	 <!-- 合同订单id -->
	<input type ="hidden" id="indentId" name ="indentID" value="${orderMateriel.indentId}"/>
	<!-- 款式id -->
	<input type ="hidden" id="styleId" name ="styleID" value="${orderMateriel.styleId}"/>
</c:if>
<!-- 合同id -->
<input type ="hidden" id="contractId" name ="contractID" value="${orderMateriel.contractId}"/>
<!-- 客户id -->
<input type ="hidden" id="ognizationId" name ="ognizationID" value="${orderMateriel.ognizationId}"/>
<!-- 订单通知单状态 -->
<input type ="hidden" id="stockStatus" name ="contractIndentEntity.stockStatus" value="${orderMateriel.contractIndentEntity.stockStatus}"/>
   <c:choose>
   <c:when test="${produceNotice.noticeFlag == '1'}">
   <div class="items clearfix">
   		<div class="col-33 clearfix">
        <!-- 客户 -->
            <p class="tit" style="width: 80px">客户</p>
            <label>${orderMateriel.ognizationName}</label>
        </div>
        <div class="col-33 clearfix">
        <!-- 定制合同号 -->
            <p class="tit" style="width: 80px">定制合同号</p>
            <label>${orderMateriel.contractNo}</label>
        </div>
        <div class="col-33 clearfix">
        <!-- 交货日期 -->
            <p class="tit" style="width: 80px">交货日期</p>
            <label>${produceNotice.remarks}</label>
        </div>
   </div>
   </c:when>
   <c:otherwise>
   <div class="items clearfix">
        <div class="col-33 clearfix haveToBox">
        <!-- 合同订单号 -->
            <p class="tit" style="width: 80px">合同订单号</p>
            <input type="text" id="ognizationName" value="${orderMateriel.indentNo}" readonly="readonly" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_contractMaterialNO"/>">
            <button type="button" onclick="popup('800px','519px','${ctx}/customization/nuclearmaterial/indentSelect?indentSelectFlg=productionNotice')"><spring:message code="purchaseAdvance_edit_select"/></button>
            <p class="haveTo">*</p>
        </div>
        <div class="col-33 clearfix">
        <!-- 款　　号 -->
            <p class="tit" style="width: 80px">款　　号</p>
             <input type="text" value="${orderMateriel.styleCustomerNo}"  readonly="readonly">
        </div>
        <div class="col-33 clearfix">
        <!-- 款式名称 -->
            <p class="tit" style="width: 80px">款式名称</p>
             <input type="text" value="${orderMateriel.styleNameCn}"  readonly="readonly">
        </div>
        
    </div>
    <div class="items clearfix">
        <div class="col-33 clearfix">
        <!-- 客户名称 -->
            <p class="tit" style="width: 80px">客户名称</p>
             <input type="text" value="${orderMateriel.ognizationName}"  readonly="readonly">
        </div>
        <div class="col-33 clearfix">
                <!-- 签订日期 -->
                    <p class="tit" style="width: 80px">签订日期</p>
                    <input type="text" readonly="readonly" value="<fmt:formatDate value="${orderMateriel.indentIssueDate}" pattern="yyyy-MM-dd" />">
                </div>
        <div class="col-33 clearfix">
                <!-- 计划交货日期 -->
                    <p class="tit" style="width: 80px">计划交货日期</p>
                    <input type="text" readonly="readonly" value="<fmt:formatDate value="${orderMateriel.indentDeliveryDate}" pattern="yyyy-MM-dd" />">
                </div>
    </div>
   </c:otherwise>
   </c:choose>
    
            <div class="items clearfix">        	
                <div class="col-33 clearfix">
                <!-- 订单数量  -->
                    <p class="tit" style="width: 80px">订单数量</p>
                    <c:if test="${produceNotice.noticeFlag==null||produceNotice.noticeFlag=='0' }">
                    	<input type="tel" id="noticeQuantity" name="noticeQuantity" value="<fmt:formatNumber value="${orderMateriel.indentQuantity}" pattern="#,##0.#####"/>" readonly="readonly">
                	</c:if>
                	<c:if test="${produceNotice.noticeFlag!=null&&produceNotice.noticeFlag!='0' }">
                    	<input type="tel" id="noticeQuantity" name="noticeQuantity" value="<fmt:formatNumber value="${produceNotice.noticeQuantity}" pattern="#,##0.#####"/>" readonly="readonly">
                	</c:if>
                </div>                	
                
            </div>
 </div>
            <div class="items clearfix">
        <div class="col-33 clearfix haveToBox">
        <!-- 生产班组  -->
            <p class="tit" style="width: 80px">生产班组</p>
            <select  name="userGroupID" id="userGroupID" style="width: 150px">
                   <option value="0"><spring:message code="order_please_choose"/></option>
                   <c:forEach items="${groupList}" var="group">
                       <option value="${group.userGroupID}" <c:if test="${produceNotice.userGroupID eq group.userGroupID }">selected="selected"</c:if>>${group.groupName}</option>
                   </c:forEach>
            </select>
            <p class="haveTo">*</p>
        </div>
         <div class="col-33 clearfix haveToBox">
                <!-- 单人生产效率 -->
                    <p class="tit" style="width: 80px">单人生产效率</p>
                    <input type="tel" id="noticeEfficiency" name="noticeEfficiency" value="${produceNotice.noticeEfficiency }">&ensp;(件/人)
                    <p class="haveTo">*</p>
                </div>
        <div class="col-33 clearfix haveToBox">
                <!-- 投产人数  -->
                    <p class="tit" style="width: 80px">投产人数</p>
                    <input type="tel" id="noticeNumber" name="noticeNumber" value="${produceNotice.noticeNumber }">&ensp;(人)
                	<p class="haveTo">*</p>
                </div>
   		</div>
    
            <div class="items clearfix haveToBox">        	
                <div class="col-33 clearfix">
                <!-- 生产周期  -->
                    <p class="tit" style="width: 80px">计划生产周期</p>
                    <input type="tel" id="noticePeriod" name="noticePeriod" value="${produceNotice.noticePeriod }" onchange="timeFun(this.id);" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceAmount"/>">&ensp;(天)
           			<p class="haveTo">*</p>
                </div>                	
                <div class="col-33 clearfix haveToBox">
                <!-- 投产日期 -->
                    <p class="tit" style="width: 80px">开始日期</p>
                    <input type="text" onblur="if(CheckDate(this)==true) timeFun(this.id);" 
								id="noticeBeginDate" name="noticeBeginDate" value="<fmt:formatDate value="${produceNotice.noticeBeginDate }" pattern="yyyy-MM-dd" />" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceDueDate"/>">
                    <p class="haveTo">*</p>
                </div>
                <div class="col-33 clearfix haveToBox">
                <!-- 清活日期 -->
                    <p class="tit" style="width: 80px">清活日期</p>
                    <input type="text" onblur="if(CheckDate(this)==true) timeFun(this.id);" 
								id="noticeEndDate" name="noticeEndDate" value="<fmt:formatDate value="${produceNotice.noticeEndDate }" pattern="yyyy-MM-dd" />" data-rule-required="true" data-msg-required="<spring:message code="purchaseAdvance_error_msg_advanceDueDate"/>">
                    <p class="haveTo">*</p>
                </div>
            </div>
            <div class="items clearfix haveToBox">        	
                <div class="col-33 clearfix">
                <!-- 实际交货日期 -->
                    <p class="tit" style="width: 80px">实际交货日期</p>
                    <input type="text" onblur="CheckDate(this);" 
								id="noticeDeliveryDate" name="noticeDeliveryDate" value="<fmt:formatDate value="${produceNotice.noticeDeliveryDate }" pattern="yyyy-MM-dd" />">
                </div>
            </div>
</div>
</form>
<script>
	window.onload = function(){
	$('.tableScrollSm').css('height','325px')
	$('td input').each(function(){
		var tdH = $(this).parents('td').height()
		$(this).css('height',tdH)
		})
	}
	var tableW = $('.tableHead').outerWidth();
	$('.tableScroll').css('width',tableW + 18 + 'px')

</script>
</body>
</html>
